home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #import "Encrypt.tlb"
- using namespace YuriEncrypt;
-
-
- struct StartUpCom {
- StartUpCom() { CoInitialize(NULL); }
- ~StartUpCom() { CoUninitialize(); }
- } _global_com_inst;
-
- void dump_com_error(_com_error &e)
- {
- printf("COM error\n");
- printf("\tCode = %08lx\n", e.Error());
- printf("\tCode meaning = %s\n", e.ErrorMessage());
- _bstr_t bstrSource(e.Source());
- _bstr_t bstrDescription(e.Description());
- printf("\tSource = %s\n", (LPCTSTR) bstrSource);
- printf("\tDescription = %s\n", (LPCTSTR) bstrDescription);
- }
-
- void main(int argc, char **argv)
- {
- IMD5Ptr pMD5;
- IMD4Ptr pMD4;
-
- char *szIn[] = {
- "",
- "a",
- "abc",
- "message digest",
- "abcdefghijklmnopqrstuvwxyz",
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
- "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
- };
-
- _bstr_t bstr("test");
-
- BSTR b(bstr);
-
- try {
- HRESULT hr = pMD5.CreateInstance(__uuidof(MD5));
- if (FAILED(hr)) _com_issue_error(hr);
-
- for (int i = 0; i < 7; i++) {
- _bstr_t bsOut = pMD5->Encrypt(szIn[i]);
- printf("MD5(%s) = %s\n\n", szIn[i], (char*)bsOut);
- }
-
- hr = pMD4.CreateInstance(__uuidof(MD4));
- if (FAILED(hr)) _com_issue_error(hr);
-
- for (i = 0; i < 7; i++) {
- _bstr_t bsOut = pMD4->Encrypt(szIn[i]);
- printf("MD4(%s) = %s\n\n", szIn[i], (char*)bsOut);
- }
- }
- catch(_com_error& e) {
- dump_com_error(e);
- return;
- }
- }
-